#include <QtGui>
#include <QTranslator>
#include <QtCore/QTextCodec>
#include "gv_setuptimedialog.h"
#include "gv_setupdatedialog.h"
#include "gv_setuptimezonedialog.h"
#include "gv_home.h"
#include "gv_setuphomedialog.h"
#include "gv_setupdetailedviewdialog.h"
#include "gv_setting.h"

extern GV_Setting *gvsetting;
extern QDialog  *dialog;
GV_SetupTimezoneDialog::GV_SetupTimezoneDialog(QWidget *parent)
       : QDialog(parent)
{
    setupUi(this);

    QTranslator translator;
    translator.load(gvsetting->GV_GetLanguage(),".");
    qApp->installTranslator(&translator);
    reloadtext();

    TimeHintsLabel->setText((QDateTime::currentDateTime().toString("hh:mm:ss")));
    DateHintsLabel->setText((QDateTime::currentDateTime().toString("yyyy-MM-dd")));

    dstenabled = false;
    timezone = 8;
    TimezonelistWidget->setCurrentRow(12+8);

    timer = new QTimer;
    connect(timer,SIGNAL(timeout()),this,SLOT(GV_chTime()));
    connect(BackButton,SIGNAL(clicked()),this,SLOT(cancel()));
    connect(CancelButton,SIGNAL(clicked()),this,SLOT(cancel()));
    connect(AcceptButton,SIGNAL(clicked()),this,SLOT(accept()));

    connect(DSTButton,SIGNAL(clicked()),this,SLOT(dst()));
    connect(TimezonelistWidget,SIGNAL(itemSelectionChanged()),this,SLOT(timezoneselect()));
    connect(DateButton,SIGNAL(clicked()),this,SLOT(setupdate()));
    connect(TimeButton,SIGNAL(clicked()),this,SLOT(setuptime()));
    connect(DetailedviewButton,SIGNAL(clicked()),this,SLOT(detailview()));

    timer->start(1000);
}
void GV_SetupTimezoneDialog::reloadtext()
{
    //NameHintsLabel->setText(tr("Zones"));
}
void GV_SetupTimezoneDialog::GV_chTime()
{
    TimeHintsLabel->setText((QDateTime::currentDateTime().toString("hh:mm:ss")));
    DateHintsLabel->setText((QDateTime::currentDateTime().toString("yyyy-MM-dd")));
}

void GV_SetupTimezoneDialog::accept()
{

    QMessageBox::about(this,"timezone","timezone:" + QString::number(timezone) + " DST:" + QString::number(dstenabled));
    QDialog *dialog1 = new GV_SetupHomeDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}

void GV_SetupTimezoneDialog::cancel()
{
    QDialog *dialog1 = new GV_SetupHomeDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}

void GV_SetupTimezoneDialog::dst()
{
    dstenabled = !dstenabled;
}
void GV_SetupTimezoneDialog::timezoneselect()
{
    timezone = TimezonelistWidget->currentRow()-12;
}

void GV_SetupTimezoneDialog::setupdate()
{
    QDialog *dialog1 = new GV_SetupDateDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}

void GV_SetupTimezoneDialog::setuptime()
{
    QDialog *dialog1 = new GV_SetupTimeDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}
void GV_SetupTimezoneDialog::detailview()
{
    QDialog *dialog1 = new GV_SetupDetailedViewDialog;
    dialog1->show();
    delete dialog;
    dialog = dialog1;
}
